package com.besttone.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;
import android.widget.SectionIndexer;

@SuppressLint("ResourceAsColor")
public class AlphabetBar extends View {
	private String[] l;
	private ListView list;
	private int mCurIdx;
	private OnSelectedListener mOnSelectedListener;
	private int m_nItemHeight;
	private SectionIndexer sectionIndexter;

	public AlphabetBar(Context paramContext) {
		super(paramContext);
		String[] arrayOfString = new String[27];
		arrayOfString[0] = "热门";
		arrayOfString[1] = "A";
		arrayOfString[2] = "B";
		arrayOfString[3] = "C";
		arrayOfString[4] = "D";
		arrayOfString[5] = "E";
		arrayOfString[6] = "F";
		arrayOfString[7] = "G";
		arrayOfString[8] = "H";
		arrayOfString[9] = "I";
		arrayOfString[10] = "J";
		arrayOfString[11] = "K";
		arrayOfString[12] = "L";
		arrayOfString[13] = "M";
		arrayOfString[14] = "N";
		arrayOfString[15] = "O";
		arrayOfString[16] = "P";
		arrayOfString[17] = "Q";
		arrayOfString[18] = "R";
		arrayOfString[19] = "S";
		arrayOfString[20] = "T";
		arrayOfString[21] = "U";
		arrayOfString[22] = "V";
		arrayOfString[23] = "W";
		arrayOfString[24] = "X";
		arrayOfString[25] = "Y";
		arrayOfString[26] = "Z";
		this.l = arrayOfString;
		this.sectionIndexter = null;
		this.m_nItemHeight = 25;
		setBackgroundColor(1157627903);
	}

	public AlphabetBar(Context paramContext, AttributeSet paramAttributeSet) {
		super(paramContext, paramAttributeSet);
		String[] arrayOfString = new String[27];
		arrayOfString[0] = "热门";
		arrayOfString[1] = "A";
		arrayOfString[2] = "B";
		arrayOfString[3] = "C";
		arrayOfString[4] = "D";
		arrayOfString[5] = "E";
		arrayOfString[6] = "F";
		arrayOfString[7] = "G";
		arrayOfString[8] = "H";
		arrayOfString[9] = "I";
		arrayOfString[10] = "J";
		arrayOfString[11] = "K";
		arrayOfString[12] = "L";
		arrayOfString[13] = "M";
		arrayOfString[14] = "N";
		arrayOfString[15] = "O";
		arrayOfString[16] = "P";
		arrayOfString[17] = "Q";
		arrayOfString[18] = "R";
		arrayOfString[19] = "S";
		arrayOfString[20] = "T";
		arrayOfString[21] = "U";
		arrayOfString[22] = "V";
		arrayOfString[23] = "W";
		arrayOfString[24] = "X";
		arrayOfString[25] = "Y";
		arrayOfString[26] = "Z";
		this.l = arrayOfString;
		this.sectionIndexter = null;
		this.m_nItemHeight = 25;
		setBackgroundColor(1157627903);
	}

	public AlphabetBar(Context paramContext, AttributeSet paramAttributeSet,
			int paramInt) {
		super(paramContext, paramAttributeSet, paramInt);
		String[] arrayOfString = new String[27];
		arrayOfString[0] = "热门";
		arrayOfString[1] = "A";
		arrayOfString[2] = "B";
		arrayOfString[3] = "C";
		arrayOfString[4] = "D";
		arrayOfString[5] = "E";
		arrayOfString[6] = "F";
		arrayOfString[7] = "G";
		arrayOfString[8] = "H";
		arrayOfString[9] = "I";
		arrayOfString[10] = "J";
		arrayOfString[11] = "K";
		arrayOfString[12] = "L";
		arrayOfString[13] = "M";
		arrayOfString[14] = "N";
		arrayOfString[15] = "O";
		arrayOfString[16] = "P";
		arrayOfString[17] = "Q";
		arrayOfString[18] = "R";
		arrayOfString[19] = "S";
		arrayOfString[20] = "T";
		arrayOfString[21] = "U";
		arrayOfString[22] = "V";
		arrayOfString[23] = "W";
		arrayOfString[24] = "X";
		arrayOfString[25] = "Y";
		arrayOfString[26] = "Z";
		this.l = arrayOfString;
		this.sectionIndexter = null;
		this.m_nItemHeight = 25;
		setBackgroundColor(1157627903);
	}

	public int getCurIndex() {
		return this.mCurIdx;
	}

	@SuppressLint("ResourceAsColor")
	protected void onDraw(Canvas paramCanvas) {
		Paint localPaint = new Paint();
		localPaint.setColor(Color.LTGRAY);
		float f = 0;
		if (this.m_nItemHeight > 25) {
			localPaint.setTextSize(20.0F);
			localPaint.setTextAlign(Paint.Align.CENTER);
			f = getMeasuredWidth() / 2;
		}
		for (int i = 0;; i++) {
			if (i >= this.l.length) {
				super.onDraw(paramCanvas);
				if (-5 + this.m_nItemHeight < 5) {
					localPaint.setTextSize(5.0F);
					break;
				}
				localPaint.setTextSize(-5 + this.m_nItemHeight);
				break;
			}
			paramCanvas.drawText(String.valueOf(this.l[i]), f,
					this.m_nItemHeight + i * this.m_nItemHeight, localPaint);
			return;
		}
	}

	protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2,
			int paramInt3, int paramInt4) {
		super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4);
		this.m_nItemHeight = ((-10 + (paramInt4 - paramInt2)) / this.l.length);
	}

	public boolean onTouchEvent(MotionEvent paramMotionEvent) {
		super.onTouchEvent(paramMotionEvent);
		int i = (int) paramMotionEvent.getY() / this.m_nItemHeight;
		int j = 0;
		if (i >= this.l.length) {
			i = -1 + this.l.length;
			this.mCurIdx = i;
			if (this.sectionIndexter == null)
				this.sectionIndexter = ((SectionIndexer) this.list.getAdapter());
			j = this.sectionIndexter.getPositionForSection(i);
		}
		while (true) {
			if (i >= 0)
				break;
			i = 0;
			this.list.setSelection(j);
			if (this.mOnSelectedListener != null)
				this.mOnSelectedListener.onSelected(j);
			setBackgroundColor(-3355444);
			return true;
		}
		return false;
	}

	public void setListView(ListView paramListView) {
		this.list = paramListView;
	}

	public void setOnSelectedListener(OnSelectedListener paramOnSelectedListener) {
		this.mOnSelectedListener = paramOnSelectedListener;
	}

	public void setSectionIndexter(SectionIndexer paramSectionIndexer) {
		this.sectionIndexter = paramSectionIndexer;
	}

	public static abstract interface OnSelectedListener {
		public abstract void onSelected(int paramInt);

		public abstract void onUnselected();
	}
}
